package com.kusen.village.raise.config;

import lombok.extern.slf4j.Slf4j;

import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
import java.lang.annotation.*;

/**
 * uid是否属于当前上下文租户
 * 注：当被校验对象为空时，校验为通过，所以如果需要校验对象必填，请自行结合相关校验注解
 * Created by Zhang JinLong(150429) on 2016-09-18.
 */
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {SameTenant.StringChecker.class})
@Documented
public @interface SameTenant {

    String message() default "{org.cloud.job.constant.SameTenant.message}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    @Slf4j
    class StringChecker implements ConstraintValidator<SameTenant, Object> {

        @Override
        public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
            log.info("StringChecker {}",o);
            return true;
        }
    }
}